import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserMapper {

        @Select("SELECT * FROM user WHERE id = #{id}")
        User getUserById(@Param("id") User getUserById(@Param("id") User selectUserById(@Param("id") Long id);
    @SelectProvider

        @Select("SELECT * FROM user WHERE 1=1")
        List<User> selectAllUsers();

        @Select("SELECT * FROM user WHERE ")
        List<User> dynamicQuery(@Param("user") User user);


    // 查询所有用户
    @Select("SELECT * FROM user")
    List<User> findAll();

    // 根据 ID 查询用户
    @Select("SELECT * FROM user WHERE id = #{id}")
    User findById(@Param("id") Long id);

    // 插入用户
    @Insert("INSERT INTO user(name, email) VALUES(#{name}, #{email})")
    @Options(useGeneratedKeys = true, keyProperty = "id") // 自动生成主键并设置到实体类中
    int insert(User user);

    // 更新用户
    @Update("UPDATE user SET name = #{name}, email = #{email} WHERE id = #{id}")
    int update(User user);

    // 删除用户
    @Delete("DELETE FROM user WHERE id = #{id}")
    int deleteById(@Param("id") Long id);
}